package com.tanhua.server.controller;

import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    @GetMapping
    public ResponseEntity findCommentsList
            (String movementId,
             @RequestParam(defaultValue = "1") int page,
             @RequestParam(defaultValue = "10") int pagesize) {
        return commentsService.findCommentList(movementId, page, pagesize);
    }
    /**
     *
     * POST /comments
     */
    @PostMapping
    public ResponseEntity saveComment(@RequestBody Map map){
        String publishId = (String) map.get("movementId");
        String content = (String) map.get("comment");
        return commentsService.saveComment(publishId, content);
    }
}
